﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace ATReaderTest
{
    public partial class Form4 : Form
    {
        public List<string> AddrList;
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();
            Array.Sort(ports);
            cbCom.Items.Clear();
            cbCom.Items.AddRange(ports);
            cbCom.SelectedIndex = 0;
            AddrList = new List<string>();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (cbCom.SelectedIndex == -1)
                return;
            checkedListBox1.Items.Add(cbCom.Text, true);
            cbCom.Items.RemoveAt(cbCom.SelectedIndex);
            if (cbCom.Items.Count != 0)
                cbCom.SelectedIndex = 0;
            else
                cbCom.Enabled = false;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            AddrList.Clear();
            for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
            {
                AddrList.Add(checkedListBox1.CheckedItems[i].ToString());
            }
            this.DialogResult = DialogResult.OK;
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            checkedListBox1.Items.Clear();
            string[] ports = SerialPort.GetPortNames();
            Array.Sort(ports);
            cbCom.Items.Clear();
            cbCom.Items.AddRange(ports);
            cbCom.SelectedIndex = 0;
            cbCom.Enabled = true;
            AddrList = new List<string>();
        }
    }
}
